﻿package org.libspark.betweenas3.core.tweens
{
	import org.libspark.betweenas3.core.ticker.ITicker;
	import org.libspark.betweenas3.core.updaters.IPhysicalUpdater;
	import org.libspark.betweenas3.tweens.ITween;
	
	/**
	 * .
	 * 
	 * @author	yossy:beinteractive
	 */
	public class PhysicalTween extends AbstractTween implements IIPhysicalTween
	{
		public function PhysicalTween(ticker:ITicker)
		{
			super(ticker, 0);
		}
		
		protected var _updater:IPhysicalUpdater;
		
		/**
		 * @inheritDoc
		 */
		public function get updater():IPhysicalUpdater
		{
			return _updater;
		}
		
		/**
		 * @private
		 */
		public function set updater(value:IPhysicalUpdater):void
		{
			_updater = value;
			
			if (_updater != null) {
				_duration = _updater.duration;
			}
		}
		
		/**
		 * @inheritDoc
		 */
		public function get target():Object
		{
			return _updater != null ? _updater.target : null;
		}
		
		/**
		 * @inheritDoc
		 */
		override protected function internalUpdate(time:Number):void 
		{
			_updater.update(time);
		}
		
		/**
		 * @inheritDoc
		 */
		override protected function newInstance():AbstractTween 
		{
			return new PhysicalTween(_ticker);
		}
		
		/**
		 * @inheritDoc
		 */
		override protected function copyFrom(source:AbstractTween):void 
		{
			super.copyFrom(source);
			
			var obj:PhysicalTween = source as PhysicalTween;
			
			_updater = obj._updater.clone() as IPhysicalUpdater;
		}
	}
}